<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Package extends Model
{

    protected $fillable = [
        'title',                #标题
        'shop_id',              #商店id
        'subtitle',             #副标题
        'image',                #主图
        'content',              #内容(图文介绍)
        'service_time',         #服务时间
        'price',                #价格
        'stock_amount',         #库存
        'view_amount',          #浏览量
        'sell_amount',          #成交量
        'sort',                 #排序
        'is_show',              #是否展示
    ];

    protected $casts = [
        'is_show' => 'boolean',
    ];

    static $IS_SHOW_MAP = [
        '否', '是',
    ];

    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id', 'id')->withDefault();
    }

    public function products()
    {
        return $this->belongsToMany(Product::class, 'package_products', 'package_id', 'product_id');
    }

    public function comments()
    {
        return $this->morphMany(Comment::class, 'object');
    }
}
